package com.lnking.lnkingplace.controller;


import com.lnking.common.http.ReturnResult;
import com.lnking.lnkingplace.model.dto.cultureEnterprise.CultureEnterpriseExportDto;
import com.lnking.lnkingplace.model.dto.fourEnterprise.FourEnterpriseExportDto;
import com.lnking.lnkingplace.model.entity.CultureEnterprise;
import com.lnking.lnkingplace.model.entity.FourEnterprise;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureAddRequest;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureSearchRequest;
import com.lnking.lnkingplace.model.request.cultureEnterprise.CultureUpdateRequest;
import com.lnking.lnkingplace.model.request.fourEnterprise.FourSearchRequest;
import com.lnking.lnkingplace.service.ICultureEnterpriseService;
import com.lnking.starter.export.utils.ExportUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 文创企业表 前端控制器
 * </p>
 *
 * @author zhangqt
 * @since 2022-10-05
 */
@Api(tags="文创企业表")
@RestController
@RequestMapping("/culture-enterprise")
public class CultureEnterpriseController {
    @Resource
    ICultureEnterpriseService cultureEnterpriseService;

    @ApiOperation("查询列表")
    @GetMapping("list")
    public ReturnResult getList(CultureSearchRequest params) {
        return ReturnResult.success(cultureEnterpriseService.pageList(params));
    }

    @PostMapping("add")
    @ApiOperation("新增")
    public ReturnResult add(@RequestBody CultureAddRequest params) throws Exception{
        cultureEnterpriseService.add(params);
        return ReturnResult.success();
    }

    @PostMapping("update")
    @ApiOperation("修改")
    public ReturnResult update(@RequestBody CultureUpdateRequest params) throws Exception{
        cultureEnterpriseService.update(params);
        return ReturnResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public ReturnResult delete(@PathVariable("id") String id) {
        cultureEnterpriseService.removeById(id);
        return ReturnResult.success();
    }

    @GetMapping("get-details")
    @ApiOperation("详情")
    public ReturnResult getDetails(String id) throws Exception{
        return ReturnResult.success(cultureEnterpriseService.getById(id));
    }

    @ApiOperation("导入")
    @PostMapping("import")
    private ReturnResult importExcel(@RequestParam("file") MultipartFile file) throws Exception{
        cultureEnterpriseService.importExcel(file);
        return ReturnResult.success();
    }

    @ApiOperation(value = "导出")
    @GetMapping(value = "/export")
    public void exportInfo(CultureSearchRequest params, HttpServletResponse response) throws Exception {
        List<CultureEnterprise> data = (List<CultureEnterprise>) cultureEnterpriseService.pageList(params);
        ExportUtils.export(data, response, CultureEnterpriseExportDto.class);
    }
}
